<?php include('scripts.php'); ?>

<script type="text/javascript" language="javascript">
$(function() {
    $("#withdrawForm").validate({
        messages : {
            transactionPassword: {
                remote: "<?php echo __('Invalid trx password'); ?>"
            }
        },
        rules : {
            "transactionPassword" : {
                required : true
                , remote: "/member/verifyTransactionPassword"
            }
        },
        submitHandler: function(form) {
            waiting();
            var ecashBalance = $('#ecashBalance').autoNumericGet();
            var withdrawAmount = parseFloat($("#cbo_ecashAmount").val());

            if (withdrawAmount > parseFloat(ecashBalance)) {
                alert("<?php echo __('In-sufficient E-Cash'); ?>");
                return false;
            } /*else if ((parseFloat(ecashBalance) /2) <= withdrawAmount) {
                alert("<?php //echo __('Amount of withdrawal requested MUST BE TWICE of amount of E-cash available in Wallet.'); ?>");
                return false;
            }*/

            form.submit();
        }
    });
});
</script>

<form action="/member/ecashWithdrawal" id="withdrawForm" name="withdrawForm" method="post">
    <div style="padding: 10px; top: 30px; width: 98%">
        <div class="portlet">
            <div class="portlet-header"><?php echo __('Withdrawal') ?></div>
            <div class="portlet-content">

                <table cellpadding="0" cellspacing="5" align="center" border="0">
                    <tr>
                        <td colspan=2 align='center'>
                        <?php if ($sf_flash->has('successMsg')): ?>
                            <div class="ui-widget">
                                <div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-highlight ui-corner-all">
                                    <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>
                                    <strong><?php echo $sf_flash->get('successMsg') ?></strong></p>
                                </div>
                            </div>
                        <?php endif; ?>
                        <?php if ($sf_flash->has('errorMsg')): ?>
                            <div class="ui-widget">
                                <div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-error ui-corner-all">
                                    <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>
                                    <strong><?php echo $sf_flash->get('errorMsg') ?></strong></p>
                                </div>
                            </div>
                        <?php endif; ?>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <strong><?php echo __('E-Cash Balance'); ?></strong>
                        </td>
                        <td>
                            <input name="ecashBalance" id="ecashBalance" tabindex="1" disabled="disabled"
                                   value="<?php echo number_format($ledgerAccountBalance, 2); ?>"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <strong><?php echo __('E-Cash Withdraw Amount'); ?></strong>
                        </td>
                        <td>
                            <select name="ecashAmount" id="cbo_ecashAmount" tabindex="2">
                                <?php
/*                                if ($maxWithdrawal > 500 && $maxWithdrawal < 5000) {
                                */?><!--
                                <option value="<?php /*echo $maxWithdrawal*/?>">USD <?php /*echo $maxWithdrawal*/?> (MAXIMUM)</option>
                                <?php /*} */?>
                                <?php
/*                                if ($maxWithdrawal >= 500) {
                                */?>
                                <option value="500">USD 500</option>
                                <?php
/*                                }
                                if ($maxWithdrawal >= 1000) {
                                */?>
                                <option value="1000">USD 1,000</option>
                                <?php
/*                                }
                                if ($maxWithdrawal >= 3000) {
                                */?>
                                <option value="3000">USD 3,000</option>
                                <?php
/*                                }
                                if ($maxWithdrawal >= 5000) {
                                */?>
                                <option value="5000">USD 5,000</option>
                                --><?php
/*                                }
                                */?>
                                <option value="500">USD 500</option>
                                <option value="1000">USD 1,000</option>
                                <option value="3000">USD 3,000</option>
                                <option value="5000">USD 5,000</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <strong><?php echo __('Transaction Password'); ?></strong>
                        </td>
                        <td>
                            <input name="transactionPassword" type="password" id="transactionPassword" tabindex="3"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan='2' align="center">
                            <font color="#dc143c"> <?php echo __('Amount of withdrawal requested MUST BE TWICE of amount of E-cash available in Wallet.')."<br>".__('Charge 5% handling fees.') ?></font>
                        </td>
                    </tr>
                    <!--<tr>
                        <td colspan='2' align='center'>
                            <?php /*if ($sf_flash->has('errorMsg')): */?>
                            <span style="font-weight: bold;; color: #ff0000;"><?php /*echo $sf_flash->get('errorMsg') */?></span>
                            <?php /*endif; */?>
                            <?php /*if ($sf_flash->has('successMsg')): */?>
                            <span style="font-weight: bold;; color: #000088;"><?php /*echo $sf_flash->get('successMsg') */?></span>
                            <?php /*endif; */?>
                        </td>
                    </tr>-->
                    <tr>
                        <td colspan=2 align='center'>
                            <input type="submit" name="Button1" value="<?php echo __('Submit') ?>" language="javascript"
                                   id="btnTransfer" tabindex="5"/>
                        </td>
                    </tr>
                </table>

                <script type="text/javascript" language="javascript">
                    var datagrid = null;
                    $(function() {
                        datagrid = $("#datagrid").r9jasonDataTable({
                            // online1DataTable extra params
                            "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
                            "extraParam" : function(aoData) { // pass extra params to server
                            },
                            "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
                                reassignDatagridEventAttr();
                            },

                            // datatables params
                            "bLengthChange": true,
                            "bFilter": false,
                            "bProcessing": true,
                            "bServerSide": true,
                            "bAutoWidth": false,
                            "sAjaxSource": "/finance/ecashWithdrawalList",
                            "sPaginationType": "full_numbers",
                            "aaSorting": [
                                [4,'desc']
                            ],
                            "aoColumns": [
                                { "sName" : "dist_id", "bVisible" : false,  "bSortable": true},
                                { "sName" : "deduct",  "bSortable": true},
                                { "sName" : "amount",  "bSortable": true},
                                { "sName" : "status_code",  "bSortable": true},
                                { "sName" : "remarks",  "bSortable": true},
                                { "sName" : "created_on",  "bSortable": true}
                                    ]
                                });
                    }); // end function

                    function reassignDatagridEventAttr() {
                    }
                </script>

                <div class="portlet">
                    <div class="portlet-header"><?php echo __('Withdrawal Status') ?></div>
                    <div class="portlet-content">

                        <table class="display" id="datagrid" border="0" width="100%">
                            <thead>
                            <tr>
                                <th></th>
                                <th><?php echo __('Withdrawal') ?></th>
                                <th><?php echo __('Amount') ?></th>
                                <th><?php echo __('Status') ?></th>
                                <th><?php echo __('Remarks') ?></th>
                                <th><?php echo __('Date') ?></th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>